﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Resources;

namespace AppNet.MultiLanguage
{
    /// <summary>
    /// Created by HaiPV
    /// 10/05/2013
    /// Translate key in multi language.
    /// </summary>
    public class Translation
    {
        private static Translation instance = null;
        private ResourceManager resourceManager; 
        private const string ROOT_RESOURCE = "AppNet.MultiLanguage.Resources.";  // File resource contain dictionary.
        private string culture; // Culture include language and country code.

        private Translation()
        {
            culture = "vi-vn";
            resourceManager = new ResourceManager(ROOT_RESOURCE + culture, typeof(Translation).Assembly);
        }

        public static Translation GetInstance
        {
            get
            {
                if (instance == null)
                {
                    instance = new Translation();
                }
                return instance;
            }
        }

        public string Culture
        {
            get
            {
                return culture;
            }

            set
            {
                culture = value;
                resourceManager = new ResourceManager(ROOT_RESOURCE + culture, typeof(Translation).Assembly);
            }
        }

        /// <summary>
        /// Translate key.
        /// </summary>
        /// <param name="key">Key want to translate</param>
        /// <returns>translated key</returns>
        public string Translate(string key)
        {
            return resourceManager.GetString(key);
        }

    }
}